"use strict";

const { Controller } = require("egg");

class gradeController extends Controller{
  async add(){
    const { ctx } = this;
    const req = ctx.request.body;
    
    const res = await ctx.service.gradeService.add({u_id:req.u_id,e_id:req.e_id,grade:req.grade,pass:req.pass,teacherShow:req.teacherShow,userCommit:req.userCommit});
    const json = ctx.helper.json(
      res.data ? res.data : null,
      res.suc ? 200 : 500,
      res.msg
    );
    ctx.body = json;
  }

  async get(){
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.gradeService.get(req);
    const json = ctx.helper.json(
      res.data ? res.data : null,
      res.suc ? 200 : 500,
      res.msg
    );
    ctx.body = json;
  }

  async getOne(){
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.gradeService.getOne(req);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }
  async update(){
    const { ctx } = this;
    const req = ctx.request.body;
    const res = await ctx.service.gradeService.updateGrade(req);
    ctx.body = ctx.helper.json(
        res.data ? res.data : null,
        res.suc ? 200 : 500,
        res.msg
    );
  }
}
module.exports = gradeController